package com.leyou.search.controller;

import com.leyou.common.pojo.PageResult;
import com.leyou.search.pojo.Goods;
import com.leyou.search.pojo.SearchRequest;
import com.leyou.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: taft
 * @Date: 2018-10-19 9:09
 */
@RestController
public class SearchController {


    @Autowired
    private SearchService searchService;

    @PostMapping("page")
    public ResponseEntity<PageResult<Goods>> queryGoods(@RequestBody SearchRequest searchRequest){
        PageResult<Goods> pageResult = searchService.queryGoods(searchRequest);

        if (null!=pageResult){
            return ResponseEntity.ok(pageResult);
        }

        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }
}
